package com.etime.shycourse.controller.ad;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.etime.shycourse.config.PageMessage;
import com.etime.shycourse.dto.CourseOfflineDto;
import com.etime.shycourse.pojo.Course;
import com.etime.shycourse.services.ad.interfaces.AdWxService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 小程序端获取广告课程数据接口
 */
@Api(tags = "微信-获取广告位置的课程数据接口")
@RestController
@RequestMapping("/wx/ad")
public class AdWxController {
    @Autowired
    private AdWxService adWxService;

    @ApiOperation("根据广告位置获取广告课程列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "placetype", value = "广告位置类型，1--首页轮播图位置，2--首页线下课程显示位置，3--分类线下课程位置"),
            @ApiImplicitParam(name = "pageNum",value = "第几页"),
            @ApiImplicitParam(name = "pageSize",value = "每页多少数据"),
    })
    @GetMapping("/by/{placetype}")
    public PageMessage<CourseOfflineDto> selectAdLogByAdPlace(@PathVariable("placetype") Long placetype, Long pageNum, Long pageSize) {
        PageMessage<CourseOfflineDto> message = new PageMessage<>();
        Page<CourseOfflineDto> coursePage = adWxService.selectCourseByPlaceType(placetype,pageNum,pageSize);
        if (coursePage != null && coursePage.getRecords().size() > 0) {
            message.setCode(1);
            message.setPagedata(coursePage);
            message.setMsg("数据查询成功");
        } else {
            message.setCode(0);
            message.setMsg("未查询到数据");
        }
        return message;
    }
}
